package company.shopee_F;

import java.util.Scanner;

// 二分查找 设置一个每分钟的步数 依次减小
//8 5 6 5 6 7 6 6 3 1
// 11
public class Shopee02A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[n];
        // 最大的一步 最大值
        int left = -1;
        // 总步数  求和
        int right = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
            left = Math.max(left, arr[i]);
            right += arr[i];
        }
        while (left < right) {
            int mid = (left + right) >> 1;
            int cmp = check(arr, mid, m);
            if (cmp == -1) {
                // 花费时间小于m，应缩小step
                right = mid - 1;
            } else if (cmp == 1) {
                // 花费时间大于m，应增大step
                left = mid + 1;
            } else {
                // 进一步缩小step
                right = mid;
            }
        }
        System.out.println(left);
        sc.close();
    }

    // 每分钟走step步，若花费时间小于m分钟，返回-1，若相等，返回零，若大于，返回1
    private static int check(int[] arr, int step, int m) {
        int sum = 0;
        int num = 1;
        for (int value : arr) {
            if (sum + value <= step) {
                //累加
                sum += value;
            } else {
                //清零
                sum = value;
                num++;
            }
        }
        return Integer.compare(num, m);
    }
}
